using UnityEngine;
using System.Collections;

public class lib {
	public static Texture2D rotateTexture(Texture2D textureIn, int rotation){
		Texture2D textureOut;
		switch (rotation) {
		case 0:
			return textureIn;
			break;
		case 90:
			textureOut = new Texture2D(textureIn.height, textureIn.width);
			textureOut.filterMode = textureIn.filterMode;
			for (int i = 0; i < textureOut.width; i++) {
				for (int d = 0; d < textureOut.height; d++) {
					textureOut.SetPixel(i, d, textureIn.GetPixel(d, textureOut.width-i-1));
				}
			}
			textureOut.Apply();
			return textureOut;
			break;
		case 180:
			textureOut = new Texture2D(textureIn.width, textureIn.height);
			textureOut.filterMode = textureIn.filterMode;
			for (int i = 0; i < textureOut.width; i++) {
				for (int d = 0; d < textureOut.height; d++) {
					textureOut.SetPixel(i, d, textureIn.GetPixel(textureOut.width-i-1, textureOut.height-d-1));
				}
			}
			textureOut.Apply();
			return textureOut;
			break;
		case 270:
			textureOut = new Texture2D(textureIn.height, textureIn.width);
			textureOut.filterMode = textureIn.filterMode;
			for (int i = 0; i < textureOut.width; i++) {
				for (int d = 0; d < textureOut.height; d++) {
					textureOut.SetPixel(i, d, textureIn.GetPixel(textureOut.height-d-1, i));
				}
			}
			textureOut.Apply();
			return textureOut;
			break;
		default:
			return textureIn;
		break;
		}
	}
}
